# -*- coding: utf-8 -*-
"""
@File: insert_announcements.py.py
@author: chenxialin
@time: 4月 08, 2025 10:12
"""
import random
from datetime import timedelta
from django.core.management.base import BaseCommand
from django.utils.timezone import now
from book.models import Announcement

class Command(BaseCommand):
    help = "Insert 10 test announcements into the database"

    def handle(self, *args, **options):
        titles = [
            "图书馆闭馆通知",
            "新书推荐活动",
            "系统维护公告",
            "暑期开放时间调整",
            "图书借阅规则更新",
            "读书分享会邀请",
            "电子资源使用指南",
            "周末特别活动",
            "图书馆搬迁通知",
            "春季阅读挑战赛"
        ]
        contents = [
            "因系统升级，图书馆将于本周五闭馆一天。",
            "本周六将举行新书推荐活动，欢迎参加。",
            "系统将于今晚进行维护，请提前保存您的工作。",
            "暑假期间开放时间调整为上午9点至下午5点。",
            "新的借阅规则已生效，请查阅详情。",
            "本周日将举办读书分享会，主题为科幻小说。",
            "如何使用图书馆的电子资源？点击查看指南。",
            "本周末有特别活动，详情请关注公告。",
            "图书馆将于下月搬迁至新址，敬请留意。",
            "参加春季阅读挑战赛，赢取精美礼品！"
        ]

        for i in range(10):
            title = titles[i]
            content = contents[i]
            is_visible = random.choice([True, False])
            published_at = now() - timedelta(days=random.randint(0, 30))
            Announcement.objects.create(
                title=title,
                content=content,
                is_visible=is_visible,
                published_at=published_at
            )

        self.stdout.write(self.style.SUCCESS("成功插入10条公告数据！"))